package join;

import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class PersonAddreReduce extends Reducer<BeanKey, Bean, NullWritable, Text> {
    @Override
    protected void reduce(BeanKey key, Iterable<Bean> values,
                          Reducer<BeanKey, Bean, NullWritable, Text>.Context context)
            throws IOException, InterruptedException {
        Bean Addre = null;
        int num = 0;
        for (Bean bean : values) {
            if (num == 0) {
                Addre = new Bean(bean); // Address地址表为values的第一个值
                num++;
            } else {
                // 其余全为person表
                // 没有list数组,节省大量内存空间
                bean.setAddreName(Addre.getAddreName());
                context.write(NullWritable.get(), new Text(bean.toString()));
            }
        }
    }
}

